package com.github.ghsea.scheduler.util;

import com.github.ghsea.scheduler.dto.Task;
import com.github.ghsea.scheduler.entity.TaskEntity;
import java.util.function.Function;

/**
 * @author guhai
 * @since 2021/6/19 1:18
 */
public class Converters {

    public static final Function<Task, TaskEntity> FROM_TASK = (task -> {
        TaskEntity taskEntity = new TaskEntity();
        taskEntity.setBizCode(task.getBizCode());
        taskEntity.setIntervalSeconds(task.getIntervalSeconds());
        taskEntity.setStopTime(task.getStopTime());

        return taskEntity;
    });

    public static final Function<TaskEntity, Task> TO_TASK = (entity -> {
        Task taskEntity = new Task();
        taskEntity.setBizCode(entity.getBizCode());
        taskEntity.setIntervalSeconds(entity.getIntervalSeconds());
        taskEntity.setStopTime(entity.getStopTime());

        return taskEntity;
    });
}
